clear all
capture log close
set more off

* Set filepaths

gl esi_data // ESI data file path here
gl cdc_data // CDC WONDER data file path here
gl figures // Output file path for figures here

* Drug overdose deaths figure

import delimited $cdc_data, clear
drop notes

twoway (connected ageadjustedrate year if race == "White", lpattern(solid) lcolor(black) msymbol(circle) mcolor(black)) (connected ageadjustedrate year if race == "Black or African American", lpattern(dash) lcolor(black) mcolor(black) msymbol(diamond_hollow)), legend(label(1 "White") label(2 "Black")) ytitle("Age-Adjusted Drug Overdose Death Rate") ylabel(,nogrid) xlabel(,nogrid) graphregion(fcolor(white)) xline(1999) xline(2010) xline(2013) text(40 2005.5 "Phase 1:" 40 2011.5 "Phase 2:" 40 2016.5 "Phase 3:") text(38 2005.5 "Prescription Opioids" 38 2011.5 "Heroin" 38 2016.5 "Synthetic Opioids") 
graph export "$figures/bw_overdose_deaths_ageadj_1999_2020.png", replace

* ESI figures

import excel $esi_data, sheet("Sheet1") firstrow clear
rename (A Black NonHispanic_White) (year black nhwhite)

twoway (connected nhwhite year, lpattern(solid) lcolor(black) mcolor(black)) (connected black year, lpattern(dash) lcolor(black) msymbol(diamond_hollow) mcolor(black)), legend(label(1 "White") label(2 "Black")) ytitle("Share 16 or Older with ESI") ylabel(0(0.2)1,nogrid) xlabel(1987(5)2017,nogrid) xtitle("Year") graphregion(fcolor(white))
graph export "$figures/bw_esi_rates_1987_2017.png", replace


